import React, { PropTypes } from 'react';
import { Button, Form, Input } from 'antd';
import FormHandle from 'components/decorator/formHandle';

const FormItem = Form.Item;

class BuildForm extends React.Component {

  handleSubmit = (e) => {
    e.preventDefault();
    this.props.form.validateFields(
      { force: true },
      (err, values) => {
        if (!err) {
          this.props.onSubmit(values);
        }
      },
    );
  }

  render() {

    const { getFieldDecorator } = this.props.form;
    const formItemLayout = {
      labelCol: { span: 7 },
      wrapperCol: { span: 14 },
    };

    const { entity } = this.props;

    return (
      <Form layout="inline">
        <FormItem
          {...formItemLayout}
          label="定时运行"
        >
          {
            getFieldDecorator('cron', {
              initialValue: entity ? entity.cron : '',
            })(
              <Input placeholder="" />,
            )
          }
        </FormItem>
        <Button type="primary" size={'default'} style={{ marginRight: '12px' }} onClick={this.handleSubmit}>保存构建</Button>
      </Form>
    );
  }
}
export default Form.create()(FormHandle(BuildForm));
